package cn.edu.flink.tutorial.wordcount;

import cn.edu.flink.tutorial.wordcount.flatmap.WordCountFlatMap;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class WordCount {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> textFile = env.readTextFile("");

        SingleOutputStreamOperator<Tuple2<String, Integer>> sum =
                textFile
                .flatMap(new WordCountFlatMap())
                .keyBy(0)
                .sum(1);

        sum.print();

        env.execute("Test");
    }
}
